$(document).ready(function() {
	
	$("button.validate").click(function() {
		window.scrollTo(0, 0);
		if (!validate('fos_user_profile_form')) {
			return false;
		}
		$("#success_notice").hide();
		$.fancybox.showActivity();   
		$.ajax({ 
                type: "POST", 
                data: $('#fos_user_profile_form').serialize(), 
                url: $('form#fos_user_profile_form').attr('action'),
                success: function(data) {
                	$.fancybox.hideActivity();
                	var response = eval(data);
                	if (response.status == "success") {
                		$("#success_notice").width('290px');
                		$("#success_notice").css('margin', 'auto');
                		$("#success_notice").show();
                	}
                	else {
                		$(response).each(function () {
                			displayErrorMessage('fos_user_profile_form', this.id, this.message);
                    });
                	}
                } 
        });
	});
});